# -*- coding: utf-8 -*-

from django.db import models
from django.conf import settings
from django.contrib.auth.models import User

import datetime, time

from django.contrib.contenttypes.models import ContentType
from comments.models import Comment

#------------------------------------------------------------------------------ 
class Article(models.Model):
    id = models.SlugField(maxlength="200", primary_key=True, editable=False)
    title = models.CharField(maxlength="200")
    user = models.ForeignKey(User, editable=False)
    date_added = models.DateTimeField(editable=False, auto_now_add=True)
    text = models.TextField(blank=True)
    
    def __str__(self):
        return self.title

    def __unicode__(self):
       return self.title

    class Admin:
        pass

    def get_comments_count(self):
        return Comment.objects.filter(object_id=self.id, content_type=ContentType.objects.get(app_label__exact='articles', model__exact='Article')).count()

#------------------------------------------------------------------------------ 
